<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<div class="setp_top">
	<div class="setp_top_btn">
		<input type="button" onclick="return validateForm()" class="btn_ok" />
		<input type="button" class="btn_cancel" onclick="prevStep()" />
	</div>
	<s:property value="#typeTxt"/>&nbsp;<s:property value="#workStatusTxt"/>
</div>
<s:if test="work.item.type == 4">
	<jsp:include page="workstep2_express.jsp"></jsp:include>
</s:if>
<s:else>
<div class="setp_main">
	<table class="table" style="width: 100%" cellpadding="0" cellspacing="0">
		<tr>
			<td>
				<table style="width: 100%" cellpadding="0" cellspacing="0">
					<tr class="title">
						<td width="300px"><span class="stress">*</span>&nbsp;货物类型：</td>
						<td><span class="stress">*</span>&nbsp;货物名称：</td>
					</tr>
					<tr>
						<td>
							<s:select id="cargoType" name="work.cargoType.id" list="#request.allCargoType" headerKey="0" headerValue="请选择" listKey="id" listValue="name" value="work.cargoType.id"></s:select>
							<font style="line-height: 45px; margin-left: -40px;">&nbsp;</font>
						</td>
						<td><input type="text" id="cargoName" name="work.cargoName" v_tips="notnull" value="<s:property value="work.cargoName"/>"/></td>
					</tr>
				</table>
			</td>
		</tr>
		<s:if test="work.item.type < 5">
			<tr class="title"><td><span class="stress">*</span>&nbsp;货主运输条款：</td></tr>
			<tr>
				<td>
					<s:select id="cy2cy1" name="work.cy2cy1.id" list="#request.allCy2cy" headerKey="0" headerValue="请选择交接方式" listKey="id" listValue="name" value="work.cy2cy1.id" cssStyle="margin-right:22px; _margin-right:16px;"></s:select>
					<s:select id="payment1" name="work.payment1.id" list="#request.allPayment" headerKey="0" headerValue="请选择运费支付方式" listKey="id" listValue="name" value="work.payment1.id" cssStyle="margin-right:22px; _margin-right:16px;"></s:select>
					<s:if test="work.item.type != 3">
						<s:select id="releaseCargoType1" name="work.releaseCargoType1.id" list="#request.allReleaseCargoType" headerKey="0" headerValue="请选择放货方式" listKey="id" listValue="name" value="work.releaseCargoType1.id"></s:select>
					</s:if>
				</td>
			</tr>
		</s:if>
		<tr>
			<td>
				<table style="width: 100%; table-layout: fixed;" cellpadding="0" cellspacing="0">
					<tr class="title">
						<td width="185px"><span class="stress">*</span>&nbsp;件数（包装）：</td>
						<td width="185px"><span class="stress">*</span>&nbsp;毛重：</td>
						<td width="185px"><span class="stress">*</span>&nbsp;体积：</td>
						<td>&nbsp;&nbsp;货值：</td>
					</tr>
					<tr>
						<td>
							<input type="text" id="quantity" name="work.quantity" v_tips="notnull,ni" value="<s:property value="work.quantity" />" class="input_s"/>
							<s:select id="packageType" name="work.packageType.id" cssClass="input_s" cssStyle="margin-left: -5px;margin-right: -5px;" list="#request.allPackageType" listKey="id" listValue="name" value="work.packageType.id"></s:select>
						</td>
						<td style="line-height: 42px;">
							<input type="text" id="grossWeight" name="work.grossWeight" v_tips="notnull,number" class="input_s" value="<s:property value="work.grossWeight"/>"/>KGS
						</td>
						<td style="line-height: 42px;">
							<input type="text" id="volume" name="work.volume" v_tips="notnull,number" class="input_s" value="<s:property value="work.volume"/>"/>CBM
						</td>
						<td style="line-height: 42px;">
							<input type="text" id="cargoValue" name="work.cargoValue" class="input_m" value="<s:property value="work.cargoValue"/>"/>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr class="title"><td>&nbsp;&nbsp;唛头：</td></tr>
		<tr>
			<td>
				<textarea id="mark" name="work.mark" class="input_xl jNiceTextarea"><s:property value="work.mark"/></textarea>
			</td>
		</tr>
		<s:if test="work.item.type <= 5">
			<tr class="title"><td>&nbsp;&nbsp;发货人：</td></tr>
			<tr>
				<td>
					<textarea id="shipper" name="work.shipper" class="input_xl jNiceTextarea"><s:property value="work.shipper"/></textarea>
				</td>
			</tr>
			<tr class="title"><td>&nbsp;&nbsp;收货人：</td></tr>
			<tr>
				<td>
					<textarea id="consignee" name="work.consignee" class="input_xl jNiceTextarea"><s:property value="work.consignee"/></textarea>
				</td>
			</tr>
		</s:if>
		<s:if test="work.item.type < 5">
			<tr class="title"><td>&nbsp;&nbsp;通知人：</td></tr>
			<tr>
				<td>
					<textarea id="notifyParty" name="work.notifyParty" class="input_xl jNiceTextarea"><s:property value="work.notifyParty"/></textarea>
				</td>
			</tr>
			<tr class="title"><td>&nbsp;&nbsp;供货人：</td></tr>
			<tr>
				<td>
					<textarea id="supplier" name="work.supplier" class="input_xl jNiceTextarea"><s:property value="work.supplier"/></textarea>
				</td>
			</tr>
		</s:if>
	</table>
</div>
<script>
	var preErrorId = [];
	function validateForm(){
		var errorId = [];
		if($('#cargoType').val() == 0){
			errorId[errorId.length] = 'cargoType';
		}
		if($('#cargoName').val().trim().length == 0){
			errorId[errorId.length] = 'cargoName';
		}
		if($('#type').val() < 5){  //卡车运输和其它委托项目不需要验证 
			if($('#cy2cy1').val() == 0){
				errorId[errorId.length] = 'cy2cy1';
			}
			if($('#payment1').val() == 0){
				errorId[errorId.length] = 'payment1';
			}
			if($('#releaseCargoType1').val() == 0){
				errorId[errorId.length] = 'releaseCargoType1';
			}
		}
		if($('#quantity').val().trim().length == 0 || isNaN($('#quantity').val())){
			errorId[errorId.length] = 'quantity';
		}
		if($('#packageType').val() == '' || $('#packageType').val() == 0){
			errorId[errorId.length] = 'packageType';
		}
		if($('#grossWeight').val().trim().length == 0 || isNaN($('#grossWeight').val())){
			errorId[errorId.length] = 'grossWeight';
		}
		if($('#volume').val().trim().length == 0 || isNaN($('#volume').val())){
			errorId[errorId.length] = 'volume';
		}
		for(i=0; i<preErrorId.length; i++){
			normalCssJNice(preErrorId[i]);
		}
		if(errorId.length > 0){
			preErrorId = errorId;
			for(i=0; i< errorId.length; i++){
				errorCssJNice(errorId[i]);
			}
			return;
		}
		var params = $("#workForm").serialize();
		$.post('cts/workStep2?save=true',params,function(result){
			if(result.trim() == 'null'){
				alert('订单不存在或已经被删除');
			}else if(result.trim() == 'status5'){
				alert('该订单已归档');
			}else if(result.trim() == 'ok'){
				nextStep();
			}else{
				alert('保存失败');
			}
		})
	}
</script>
</s:else>